
let loadURL = (url, callback)=>{

    ogre.loadResource({ url: url, type: 'jpg' }, null, 2,  
        (res)=>
        {   
            if (res)
            {
                callback && callback(res)
            }
            else
            {
                ogre.loadResource(url , null, 2,  
                    (res)=>
                    {
                        callback && callback(res)
                    }
                )
            }
        }
    ) 
}

let loadDefault = (sprite)=>{

}

let load = (node, url)=>{

    let sprite = node.getComponent(cc.Sprite)
    if (!sprite)
    {
        return
    }

    if (url)
    {
        loadURL(url, 
            (res)=>{

                if (!node.isValid)
                {
                    return
                }

                if (res)
                {
                    sprite.spriteFrame = new cc.SpriteFrame(res)
                }
                else
                {
                    Log.w('AvatarLoader', 'load avatar fail: ' + url)
                    
                    loadDefault(sprite)
                }
            }
        )
    }
    else
    {
        loadDefault(sprite)
    }      
}

module.exports = load
